// 应用构造器
App({
  onLaunch() {
    const token = wx.getStorageSync('token')
    if(token) {
      wx.checkSession({
        success () {
          wx.request({
            url: 'http://localhost:3000/isAuth',
            method: 'post',
            data: {
              token
            },
            success: (result) => {
              console.log(result)
            }
          })
        },
        fail () {
          wx.login({
            success: ({code}) => {
              wx.request({
                url: 'http://localhost:3000/auth',
                method: 'post',
                data: {
                  code
                },
                success: (result) => {
                  wx.setStorageSync('token', result.data)
                }
              })
            }
          })
        }
      })
    } else {
      console.log('fail')
    }
  }
})
